package com.xj.service;

import com.xj.dao.BookDAO;
import com.xj.model.Book;
import com.xj.model.enums.BookStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by xiongjie on 2020/3/1.
 */
@Service
public class BookService {

    @Autowired
    private BookDAO bookDAO;

    /**
     * 查询全部book
     * @return
     */
    public List<Book> selectAll() {
        return bookDAO.selectAll();
    }

    /**
     * 添加book
     * @param book
     * @return
     */
    public int addBook(Book book) {
        return bookDAO.addBook(book);
    }

    /**
     * 删除book，本质是修改状态
     * @param id
     */
    public void deleteBook(int id) {
        bookDAO.updateBookStatus(id, BookStatusEnum.DELETE.getValue());
    }

    /**
     * 恢复book，本质是修改状态
     * @param id
     */
    public void recoverBook(int id) {
        bookDAO.updateBookStatus(id, BookStatusEnum.NORMAL.getValue());
    }

}
